#coding=utf-8
import os
import random
import shutil
path_dicts={}

res_path=os.path.join(os.getcwd(), "res")  # 获取绝对路径
out_path=os.path.join(os.getcwd(), "out")  # 获取绝对路径


#old_path  原路劲
#new_path  修改完毕后的新路劲
def rename_res_path(old_path,new_path):
	old_path=os.path.join(res_path, old_path)  # 获取绝对路径
	new_path=os.path.join(out_path, new_path)  # 获取绝对路径
	

	parentPath=new_path[0:new_path.rfind('\\')]
	if not os.path.isdir(parentPath):
		os.makedirs(parentPath)
	shutil.copyfile(old_path, new_path)
	# # os.renames(old_path, new_path)
	print old_path+"   rename file success  "+new_path
# 获取指定的文件
def get_res_file(prefix,path,old_path,new_path):
	files = os.listdir(path)
	for file in files:
		file_path = os.path.join(path, file)  # 获取绝对路径
		if os.path.isdir(file_path):   #如果是文件夹  
			# if file!="UI" and file!="fontnum" and file!="Font"  and file!="font" and file!="Dragon" and file!="dragon" and file!="rank" and file!="Json" and file!="json" and file!="Challenge":
			# index=file.find(prefix+"_")
			# if index==-1:
			# 	_old_path=old_path+file+"/"
			# 	_new_path=new_path+prefix+"_"+file+"/"
			# 	get_res_file(prefix,file_path,_old_path,_new_path)
			# else:
			# 	print file+" ---"+prefix+ " prefix already existed "
			_old_path=os.path.join(old_path, file)
			_new_path=os.path.join(new_path, file)
			get_res_file(prefix,file_path,_old_path,_new_path)
		else:
			_old_path=os.path.join(old_path, file)
			_new_path=os.path.join(new_path, prefix+file)
			path_dicts[_old_path]=_new_path
			rename_res_path(_old_path,_new_path)
			
if __name__ == '__main__':
	prefix=raw_input("please input prefix:")  #输入前缀
	print "----------- start rename all res-------------"
	get_res_file(prefix,res_path,"","")
	